package com.zjq.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zjq.dao.BookMapper;
import com.zjq.pojo.Author;
import com.zjq.pojo.BookKind;
import com.zjq.pojo.Books;
import com.zjq.pojo.Comments;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

public class BookServiceImpl implements BookService {

    public BookMapper bookMapper;

    public void setBookMapper(BookMapper bookMapper) {
        this.bookMapper = bookMapper;
    }


    public List<Books> queryAllBook() {
        return bookMapper.queryAllBook();
    }


    /*public PageInfo<Books> queryAllBookByPage(Integer currentPage, Integer pageSize) {
        List<Books> books = bookMapper.queryAllBook();
        PageInfo<Books> pageInfo = new PageInfo<Books>(books);
        if(currentPage==pageInfo.getTotal())
            pageInfo.setList(books.subList((currentPage-1)*pageSize, books.size()));
        else
            pageInfo.setList(books.subList((currentPage-1)*pageSize, (currentPage-1)*pageSize+pageSize));
        return pageInfo;
    }*/

    public Books queryBookById(int id) {
        return bookMapper.queryBookById(id);
    }

    public int addBook(Books book) {
        return bookMapper.addBook(book);
    }

    public int deleteBookById(int id) {
        return bookMapper.deleteBookById(id);
    }

    public int updateBook(Books books) {
        System.out.println("=======================>>>>>>"+books);
        return bookMapper.updateBook(books);
    }

    public List<Books> queryBookByName(String name) {
        List<Books> employeeList = bookMapper.queryBookByName(name);
        return employeeList;
    }

    public int addBookKind(BookKind bookKind) {
        return bookMapper.addBookKind(bookKind);
    }

    public List<BookKind> queryBookKind() {
        return bookMapper.queryBookKind();
    }

    public int deleteBookKindById(int id) {
        return bookMapper.deleteBookKindById(id);
    }

    public List<Books> queryBookByKindId(int bookkindId) {
        return bookMapper.queryBookByKindId(bookkindId);
    }

    public List<Books> queryBookByType(int type) {
        return bookMapper.queryBookByType(type);
    }

    public List<Books> queryBookByKindL(int id) {
        return bookMapper.queryBookByKindL(id);
    }

    public List<Comments> queryCommentsById(int pId) {
        return bookMapper.queryCommentsById(pId);
    }

    public List<Author> queryAuthorByName(String name) {
        return bookMapper.queryAuthorByName(name);
    }

    public int addAuthor(Author author) {
        return bookMapper.addAuthor(author);
    }

    /*public PageInfo<Books> querybook(Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        List<Books> books = bookMapper.queryAllBook();
        PageInfo<Books> pageInfo = new PageInfo<Books>(books);

        return pageInfo;
    }*/

}
